package com.health.httpbean.format;

import android.text.TextUtils;
import android.util.Log;

import com.blankj.utilcode.util.TimeUtils;
import com.health.httpbean.model.UserInfoBean;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.viewscontrols.NovaApplication;

import java.util.List;

/**
 * author : xiaoxin
 * date   : 2020/12/25 9:39
 * desc   :
 * update :
 */
public class ArchiveFormatData {

    public static UserInfoBean formatArchive(ARCHIVE_BASEINFO archiveBaseinfo) {

        Log.e("xiaoxin", "formatArchive: " + archiveBaseinfo.toString() );
//        HttpDataBean httpDataBean = new HttpDataBean();
        UserInfoBean userInfoBean = new UserInfoBean();
//        httpDataBean.QueryType = "UserInfo";
//        httpDataBean.Data = userInfoBean;
        try {
            userInfoBean.setCardID(archiveBaseinfo.getIDCARD());
            userInfoBean.setUserName(archiveBaseinfo.getCUSTOMERNAME());
            userInfoBean.setUserSex(archiveBaseinfo.getSEX().equals("DM01-08_1") ? "1" : "2");
            userInfoBean.setUserNation(formatNation(archiveBaseinfo.getNATION()));
            userInfoBean.setUserDTel(archiveBaseinfo.getPHONE());
            userInfoBean.setUserAddressNew(archiveBaseinfo.getADDR());
            String Province = archiveBaseinfo.getPROVINCE() + "000000000000";
            userInfoBean.setProvince(Province.substring(0,12));
            String City = archiveBaseinfo.getCITY()  + "000000000000";
            userInfoBean.setCity(City.substring(0,12));
            String County = archiveBaseinfo.getCOUNTY() + "000000000000";
            userInfoBean.setCounty(County.substring(0,12));
//            String Town = archiveBaseinfo.getUPDATEORG() + "000000000000";
//            userInfoBean.setTown(Town.substring(0,12));
//            String Village = archiveBaseinfo.getSTREET() + "000000000000";
//            userInfoBean.setVillage(Village.substring(0,12));
            //这里Town 的字段数据 取Village里面的
            String Town = archiveBaseinfo.getSTREET() + "000000000000";
            userInfoBean.setTown(Town.substring(0,12));
//            String Village = archiveBaseinfo.getSTREET() + "000000000000";
            userInfoBean.setVillage("");
            try {
                userInfoBean.setUserBirthday(
                        TimeUtils.millis2String(archiveBaseinfo.getBIRTHDAY().getTime(), "yyyy-MM-dd"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return userInfoBean;
    }

    /**
     * 格式化名族
     * @param nation DM01-01_01 汉族
     * @return
     */
    public static String formatNation(String nation) {
        try {
            if (TextUtils.isEmpty(nation)) return nation;

            if (nation.startsWith("DM")) {
                List<BD_DD_INFO> nationList = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                        "PARENTID = 'DM01-01'");
                for (int i = 0; i < nationList.size(); i++) {
                    if (nation.equals(nationList.get(i).getID())) {
                        return nationList.get(i).getDATANUM();
                    }
                }
            } else if (nation.equals("汉族")) {
                return "01";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nation;
    }
}
